import service from '@/utils/request'
import {
  getToken
} from '@/utils/getToken'

// 创建axios实例
import axios from 'axios'

const httpRequest = (url, data, method = 'post') => {
  return service({
    url: url,
    method: method,
    data: data
  })
}

const BaseURL = process.env.VUE_APP_BASEURL || location.origin
const Token = getToken()
const AxiosInit = axios.create({
  baseURL: BaseURL + '/api/',
  timeout: 2 * 60 * 1000,
  headers: {
    'Content-Type': 'multipart/form-data',
    Authorization: Token
  },
  withCredentials: true
})

const AxiosInits = axios.create({
  baseURL: BaseURL + '/api/',
  timeout: 15 * 1000,
  headers: {
    'Content-Type': 'application/json',
    Authorization: Token
  },
  withCredentials: true
})

const UploadRequest = (url, data, method = 'post') => {
  return AxiosInit({
    url: url,
    method: method,
    data: data
  })
}

const SpecialRequest = (url, data, method = 'post') => {
  return AxiosInits({
    url: url,
    method: method,
    data: data
  })
}

export {
  httpRequest,
  UploadRequest,
  SpecialRequest
}
